package com.pandora.credit.mongo.entity;

import com.pandora.credit.exception.InvalidResponseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author developer
 */
public abstract class AbstractReportAfterFormat {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());
    protected AbstractReport report;
    protected ReportMetaData metaData;

    public void formatReport(AbstractReport report) {
        try {
            setMetaData(getMetaDataByReport(report));
        } catch(Exception e) {
            throw new InvalidResponseException();
        }
        setReport(dealReportData(report));
    }

    /**
     * get metadata from datasource in the report
     * @param report
     * @return
     */
    protected abstract ReportMetaData getMetaDataByReport(AbstractReport report);

    /**
     * each sub class related with different report type and responsible for dealing with the report
     * @param report
     * @return
     */
    protected abstract AbstractReport dealReportData(AbstractReport report);


    public AbstractReport getReport() {
        return report;
    }

    public void setReport(AbstractReport report) {
        this.report = report;
    }

    public ReportMetaData getMetaData() {
        return metaData;
    }

    public void setMetaData(ReportMetaData metaData) {
        this.metaData = metaData;
    }
}
